package com.four.reimbursemanage.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.four.reimbursemanage.entity.OutmemberApply;
import com.four.reimbursemanage.entity.Payapply;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

@Mapper
public interface OutmemberApplyMapper extends BaseMapper<OutmemberApply> {
    /**
     * 查询外聘人员费申请列表
     */
    @Select("<script>" +
            "SELECT * FROM outmember_apply" +
            "<where>" +
            "    <if test=\"outdate != null\">" +
            "      and outdate = #{outdate}" +
            "   </if>" +
            "    <if test=\"state != null\">" +
            "      and state = #{state}" +
            "   </if>" +
            "</where>" +
            "limit #{start}, #{size}" +
            "</script>")
    public List<OutmemberApply> selectOutmemberList(int start, int size, Date outdate, Integer state);

    /**
     * 查询本人外聘人员费申请列表
     */
    @Select("<script>" +
            "SELECT * FROM outmember_apply" +
            "<where>" +
            "    <if test=\"outdate != null\">" +
            "      and outdate = #{outdate}" +
            "   </if>" +
            "    <if test=\"state != null\">" +
            "      and state = #{state}" +
            "   </if>" +
            "    <if test=\"number != null\">" +
            "      and number = #{number}" +
            "   </if>" +
            "</where>" +
            "limit #{start}, #{size}" +
            "</script>")
    public List<OutmemberApply> selectUser(int start, int size, Date outdate, Integer state, String number);

    /*分页*/
    @Select("<script>" +
            "SELECT count(*) FROM outmember_apply" +
            "<where>" +
            "    <if test=\"outdate != null\">" +
            "      and outdate = #{outdate}" +
            "   </if>" +
            "    <if test=\"state != null\">" +
            "      and state = #{state}" +
            "   </if>" +
            "</where>" +
            "</script>")
    public int countOutmemberApply( Date outdate, Integer state);

    /*本人分页*/
    @Select("<script>" +
            "SELECT count(*) FROM outmember_apply" +
            "<where>" +
            "    <if test=\"outdate != null\">" +
            "      and outdate = #{outdate}" +
            "   </if>" +
            "    <if test=\"state != null\">" +
            "      and state = #{state}" +
            "   </if>" +
            "    <if test=\"number != null\">" +
            "      and number = #{number}" +
            "   </if>" +
            "</where>" +
            "</script>")
    public int countOutmemberApplyUser( Date outdate, Integer state, String number);

    /**
     * 新增外聘人员费申请
     *
     */
    @Insert("insert into outmember_apply (number,name,outdate,cost,is_sign,cost_number,cost_sum,state)" +
            "values (#{number},#{name},#{outdate},#{cost},#{is_sign},#{cost_number},#{cost_sum},4)")
    public int insertOutmemberApply(OutmemberApply outmemberApply);

    /**
     * 修改外聘人员费申请
     */
    @Update("<script>" +
            "  update outmember_apply" +
            "        <set>" +
            "            <if test=\"null != name\"> " +
            "                name = #{name}," +
            "            </if>" +
            "            <if test=\"null != outdate\"> " +
            "                outdate = #{outdate}," +
            "            </if>" +
            "            <if test=\"null != cost\"> " +
            "                cost = #{cost}," +
            "            </if>" +
            "            <if test=\"null != is_sign\"> " +
            "                is_sign = #{is_sign}," +
            "            </if>" +
            "            <if test=\"null != cost_number\"> " +
            "                cost_number = #{cost_number}," +
            "            </if>" +
            "            <if test=\"null != cost_sum\"> " +
            "                cost_sum = #{cost_sum}," +
            "            </if>" +
            "            <if test=\"null != state\"> " +
            "                state = #{state}," +
            "            </if>" +
            "        </set>" +
            "        where id = #{id}" +
            "</script>")
    public int updateOutmemberApply(OutmemberApply outmemberApply);

    /*修改审批状态*/
    @Update("<script>" +
            "update  outmember_apply " +
            "        <set>" +
            "            <if test=\"null!= state\">" +
            "                state =#{state}," +
            "            </if>" +
            "        </set>" +
            "        where id =#{id}" +
            "</script>")
    public int updateStateById(OutmemberApply outmemberApply);
}
